package com.shenmazong.servereduuser.service.impl;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shenmazong.servereduuser.entity.TbStaffPosition;
import com.shenmazong.servereduuser.mapper.TbStaffPositionMapper;
import com.shenmazong.servereduuser.service.TbStaffPositionService;
import com.shenmazong.utils.ResultResponse;
import com.shenmazong.vo.BatchChooseIdVo;
import com.shenmazong.vo.ListParamVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 *
 */
@Service
public class TbStaffPositionServiceImpl implements TbStaffPositionService {

    @Autowired
    private TbStaffPositionMapper staffPositionMapper;

    @Override
    public ResultResponse createStaffPosition(TbStaffPosition staffPosition) {
        try {
            staffPositionMapper.insert(staffPosition);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultResponse.FAILED(404,"添加职工岗位失败");
        }
        return ResultResponse.SUCCESS(200,"添加职工岗位成功");
    }

    @Override
    public ResultResponse deleteStaffPositon(BatchChooseIdVo idVo) {
        if(idVo.getIds().size()<=0){
            return ResultResponse.FAILED(404,"请至少选择一个职工岗位记录");
        }

        try {
            staffPositionMapper.deleteBatchIds(idVo.getIds());
        } catch (Exception e) {
            e.printStackTrace();
            return ResultResponse.FAILED(500,"删除失败");
        }
        return ResultResponse.SUCCESS(200,"删除成功");
    }

    @Override
    public ResultResponse getAllStaffPosition(ListParamVo paramVo) {
        IPage<TbStaffPosition> page=new Page<>(paramVo.getCurrent()-1,paramVo.getSize());
        page = staffPositionMapper.selectPage(page, null);
        return ResultResponse.SUCCESS(200,"获取成功",page);
    }

    @Override
    public ResultResponse updateStaffPosition(TbStaffPosition staffPosition) {
        if(staffPosition.getPositionId()==null || staffPosition.getPositionId()==0){
            return ResultResponse.FAILED(404,"您未选择要更新的职工记录");
        }
        TbStaffPosition tbStaffPosition = staffPositionMapper.selectById(staffPosition.getPositionId());
        if(tbStaffPosition==null){
            return ResultResponse.FAILED(500,"修改的记录不存在");
        }

        try {
            staffPositionMapper.updateById(staffPosition);
        } catch (Exception e) {
            e.printStackTrace();
            return ResultResponse.FAILED(400,"修改失败");
        }

        return ResultResponse.SUCCESS(200,"更新记录成功");
    }
}




